import cv2

url = 'http://admin:admin@192.168.1.102:8081/'

faceCascade = cv2.CascadeClassifier('tyl_libs/haarcascade_frontalface_default.xml')
video = cv2.VideoCapture(url)

while video.isOpened():
    retval, img = video.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    if not retval:
        break
    faces = faceCascade.detectMultiScale(gray, 1.1)
    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)
    cv2.imshow('img', img)
    key = cv2.waitKey(1)
    # 按下空格键退出
    if key == 32:
        break

cv2.waitKey()
cv2.destroyAllWindows()
